//
// Created by bjliuyong on 2021/7/11.
//

#ifndef GC_CLASSFILESTREAM_H
#define GC_CLASSFILESTREAM_H

#include "../utilities/globalDefinitions.h"

class ClassFileStream {
private:
    u1*   _buffer_start; // Buffer bottom
    u1*   _buffer_end;   // Buffer top (one past last element)
    u1*   _current;      // Current buffer position
    const char* _source; // Source of stream (directory name, ZIP/JAR archive name)
    bool  _need_verify;  // True if verification is on for the class file

public:
    // Constructor
    ClassFileStream(u1* buffer, int length, const char* source);
    // Buffer access
    u1* buffer() const           { return _buffer_start; }
    int length() const           { return _buffer_end - _buffer_start; }
    u1* current() const          { return _current; }
    void set_current(u1* pos)    { _current = pos; }
    const char* source() const   { return _source; }
    void set_verify(bool flag)   { _need_verify = flag; }

    // Read u4 from stream
    //u4 get_u4(TRAPS);
    u4 get_u4_fast() {
        u4 res = 1;
        _current += 4;
        return res;
    }
};

#endif //GC_CLASSFILESTREAM_H
